import { BaseItem } from "../../common/BaseItem";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { DataEvent } from "../../../events/DataEvent";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Language } from "../../../../../extend/language/Language";
import { EffectManager } from "../../../manager/EffectManager";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { SkillConfig } from "../../../resource/SkillConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ToolTipInfo } from "../../../model/ToolTipInfo";
import { Tooltip } from "../../common/tooltip/Tooltip";
import { TSkill } from "../../../../../Message/Db/Tables/TSkill";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { _type } from "../../../../../this/_type";
type int = number;
//class PetSpecialSkillItem
    
    export  class PetSpecialSkillItem extends BaseItem
    {
        constructor()
        {
            super();
            this.doubleClickEnabled = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            this.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onDoubleClickHandler);
            Dispatcher.addEventListener(EventName.PetSpecialSkillItemSelect, this.onSelectHandler);
            return;
        }

        protected onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var onClickHandler: Function;

            var loc1;
            e = arg1;
            if (this._type != PetSpecialSkillItem.CAN_STUDY) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetSpecialSkillItemSelect, {"skillId": this._skill.skillId, "skillType": _type}));
            }
            else 
            {
                onClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetSkillStudy, _skill.skillId));
                    }
                    return;
                }
                Alert.show(Language.getStringByParam(28085, this._skill.skillName), null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            return;
        }

        /* internal  */onDoubleClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._type == PetSpecialSkillItem.HAS_STUDY || this._isUseing) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetSpecialSkillItemSelect, {"skillId": this._skill.skillId, "skillType": _type}));
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetSpecialSkillPutOnOrPutDown));
            }
            return;
        }

        protected onSelectHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data.skillId as int;
            this._isSelect = this._skill.skillId == loc1;
            this.setFilters();
            return;
        }

        protected setFilters(): void
        {
            if (this._type != PetSpecialSkillItem.CAN_STUDY) 
            {
                if (this._type != PetSpecialSkillItem.NO_STUDY) 
                {
                    EffectManager.glowFilterUnReg(_bitmap);
                    _bitmap.filters = this._isSelect ? [FilterConst.itemChooseFilter] : [];
                    this._canStudy.text = this._isUseing ? Language.getString(28079) : "";
                }
                else 
                {
                    EffectManager.glowFilterUnReg(_bitmap);
                    _bitmap.filters = this._isSelect ? [FilterConst.colorFilter, FilterConst.itemChooseFilter] : [FilterConst.colorFilter2];
                    this._canStudy.text = "";
                }
            }
            else 
            {
                EffectManager.glowFilterReg(_bitmap);
                this._canStudy.text = Language.getString(28067);
            }
            return;
        }

        /* internal  */addLightMask(): void
        {
            if (!this._lightMask) 
            {
                this._lightMask = EffectManager.getLightMask(45, 45);
                this._lightMask.x = -3;
                this._lightMask.y = -3;
                this.addChildAt(this._lightMask, 0);
            }
            return;
        }

        /* internal  */removeLightMask(): void
        {
            if (this._lightMask) 
            {
                EffectManager.disposeLightMask(this._lightMask);
                this._lightMask = null;
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            ObjCreate.createBitmap(ImagesConst.PackItemBg, -3, -3, this);
            super.createChildren();
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 16777215, null, null, null, null, null, flash.text.TextFormatAlign.RIGHT);
            this._Lv = ObjCreate.createGTextField("", 13, 19, 20, 20, this, loc1);
            this._bgOne = ObjCreate.createBg(-10, 38, 55, 20, this, ImagesConst.FightingStrgBg);
            this._bgOne.alpha = 0.7;
            this._canStudy = ObjCreate.createGTextField("", -4, 40, 40, 20, this, GlobalStyle.textFormat6);
            return;
        }

        public /* override */ get toolTipData()
        {
            var loc3=null;
            var loc4=null;
            var loc1="";
            var loc2="";
            if (this._skill) 
            {
                loc2 = GameDefConfig.instance.getSkillUseType(this._skill.useType).name;
                loc1 = loc1 + ("<font color=\'#F5FF00\'size=\'14\'><b>" + this._skill.skillName + "</b></font><br>");
                if (this._skillLevel > 0) 
                {
                    loc3 = SkillConfig.instance.getInfoByName((this._skill.skillId + this._skillLevel - 1));
                    loc1 = loc1 + HTMLUtil.addColor(Language.getString(54088) + "    Lv." + loc3.skillLevel + "<br><br>", "#a768c6");
                    loc1 = loc1 + HTMLUtil.addColor(loc3.skillDescription + "<br><br>", "#ffffff");
                    loc4 = SkillConfig.instance.getInfoByName(loc3.skillId + 1);
                }
                else 
                {
                    loc3 = this._skill;
                    loc4 = this._skill;
                }
                if (loc4) 
                {
                    loc1 = loc1 + HTMLUtil.addColor(Language.getString(28071) + "    Lv." + loc4.skillLevel + "<br><br>", "#a768c6");
                    loc1 = loc1 + HTMLUtil.addColor(loc4.skillDescription + "<br><br>", "#ffffff");
                }
                loc1 = loc1 + HTMLUtil.addColor(Language.getString(54090) + loc2 + "<br>", "#f5ff00");
                loc1 = loc1 + HTMLUtil.addColor(Language.getString(54092) + loc3.attackDistance + "<br>", "#f5ff00");
                loc1 = loc1 + HTMLUtil.addColor(Language.getString(54093) + loc3.cooldownTime / 1000 + Language.getString(54089) + "<br>", "#f5ff00");
                return new ToolTipInfo(Tooltip.ToolTipRenderType_ShortcutItem, loc1);
            }
            return null;
        }

        public set type(arg1: int)
        {
            this._type = arg1;
            this.setFilters();
            return;
        }

        public get type(): int
        {
            return this._type;
        }

        public set skill(arg1: TSkill)
        {
            this._skill = arg1;
            if (this._skill) 
            {
                this.source = this._skill.skillIcon + ".jpg";
            }
            else 
            {
                this.source = null;
            }
            this.drawNow();
            return;
        }

        public set skillLevel(arg1: int)
        {
            this._skillLevel = arg1;
            this._Lv.text = arg1 > 0 ? arg1.toString() : "";
            return;
        }

        public get skill(): TSkill
        {
            return this._skill;
        }

        public get isSelect(): Boolean
        {
            return this._isSelect;
        }

        public set isSelect(arg1: Boolean)
        {
            this._isSelect = arg1;
            return;
        }

        public set isUseing(arg1: Boolean)
        {
            this._isUseing = arg1;
            if (this._isUseing) 
            {
                this.addLightMask();
            }
            else 
            {
                this.removeLightMask();
            }
            return;
        }

        public get isUseing(): Boolean
        {
            return this._isUseing;
        }

        public onlyShowSkill(): void
        {
            this._bgOne.visible = false;
            this._canStudy.visible = false;
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            this._Lv.dispose();
            this._canStudy.dispose();
            this._bgOne.dispose();
            this._Lv = null;
            this._canStudy = null;
            this._bgOne = null;
            return;
        }

        public static /* const */CAN_STUDY: int=0;

        public static /* const */NO_STUDY: int=1;

        public static /* const */HAS_STUDY: int=2;

        protected /* var */_skill: TSkill;

        /* internal */ /* var */_skillLevel: int;

        /* internal */ /* var */_isSelect: Boolean;

        /* internal */ /* var */_type: int;

        /* internal */ /* var */_Lv: GTextFiled;

        /* internal */ /* var */_canStudy: GTextFiled;

        /* internal */ /* var */_isUseing: Boolean;

        /* internal */ /* var */_lightMask: LightMask;

        /* internal */ /* var */_bgOne: ScaleBitmap;
    }
